package org.myfram.flink.flinkonjar.application.job;

import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public abstract class BaseFlinkJob {
    public void execute(String[] args, String flinkJobName) throws Exception {
        StreamExecutionEnvironment env = getEnv();
        process(env);
        execute(env, flinkJobName);
    }

    protected abstract void process(StreamExecutionEnvironment env) throws Exception;
    protected static void execute(StreamExecutionEnvironment env, String flinkJobName) {
        try {
            env.execute(flinkJobName);
        } catch (Exception e) {
            e.printStackTrace();
        }
    };

    private static StreamExecutionEnvironment getEnv() {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        env.disableOperatorChaining();
        return env;
    }
}

